package com.rtx.edi.db.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.rtx.api.annotation.DataSourceAnnotation;
import com.rtx.edi.db.mapper.MysqlMapper;
import com.rtx.edi.db.service.DbService;

@Primary
@Service
public class MysqlDbServiceImpl implements DbService{
	
	@Autowired
	MysqlMapper mysqlMapper;

	@Override
	public List<String> queryAllTableName() {
		return mysqlMapper.showTable();
	}
	
	@DataSourceAnnotation
	public String queryTableFieldType(String datasourckey,String tablename,String column) {
		String sql ="show full COLUMNS from "+tablename+" where field = '"+column+"'";
		List<Map<String,String>> list =  mysqlMapper.queryTableFieldType(sql);
		if(!CollectionUtils.isEmpty(list)&& list.size() > 0) {
			return list.get(0).get("Type");
		}
		return null;
	}
}
